package ofpof.service.mail;

import org.springframework.core.task.TaskExecutor;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessagePreparator;

public class EmailService {

	private JavaMailSender mailSender;
	private MessageCreator messageCreator;
	private TaskExecutor taskExecutor;
	
	public EmailService(JavaMailSender mailSender, MessageCreator messageCreator, TaskExecutor taskExecutor) {
		this.mailSender = mailSender;
		this.messageCreator = messageCreator;
		this.taskExecutor = taskExecutor;
	}

	public void sendEmail(final EmailCommand emailCommand) {
	    final MimeMessagePreparator preparator = messageCreator.createMessage(emailCommand);	
	    
	    taskExecutor.execute(new Runnable() {
			@Override
			public void run() {
				mailSender.send(preparator);
			}
		});
	}

	
}
